package com.varian.tool.extend;

import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author ben
 * @since 2024/6/24
 */
public interface Branch<P, T> {

    /**
     * 条件测试
     *
     * @return Predicate
     */
    Predicate<P> tester();

    /**
     * 值工厂
     *
     * @return {@link Function}<{@link P}, {@link T}>
     */
    Function<P, T> factory();

    static <P, T> Branch<P, T> of(Predicate<P> tester, Function<P, T> factory) {
        return new Branch<>() {
            @Override
            public Predicate<P> tester() {
                return tester;
            }

            @Override
            public Function<P, T> factory() {
                return factory;
            }
        };
    }
}